package holder;

import com.example.googlemarketdemo.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import conf.constants.URLS;

import utils.BitmapHepler;
import utils.UIUtils;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import base.BaseHolder;
import bean.CategoryInfoBean;

public class CategoryNormalHolder extends BaseHolder<CategoryInfoBean> {
	
	@ViewInject(R.id.item_category_item_1)
	LinearLayout mContainerItem1;
	@ViewInject(R.id.item_category_item_2)
	LinearLayout mContainerItem2;
	@ViewInject(R.id.item_category_item_3)
	LinearLayout mContainerItem3;
	
	@ViewInject(R.id.item_category_icon_1)
	ImageView mIvIcon1;
	@ViewInject(R.id.item_category_icon_2)
	ImageView mIvIcon2;
	@ViewInject(R.id.item_category_icon_3)
	ImageView mIvIcon3;
	
	@ViewInject(R.id.item_category_name_1)
	TextView mTvName1;
	@ViewInject(R.id.item_category_name_2)
	TextView mTvName2;
	@ViewInject(R.id.item_category_name_3)
	TextView mTvName3;
	private TextView mTv;
	
	
	
	@Override
	protected View initHolderView() {
		View view = View.inflate(UIUtils.getContext(), R.layout.item_category_normal, null);
		ViewUtils.inject(this,view);
		
//		mTv = new TextView(UIUtils.getContext());
		return view;
	}

	@Override
	protected void refreshHolderView(CategoryInfoBean data) {
		setData(mTvName1,mIvIcon1,data.name1,data.url1);
		setData(mTvName2,mIvIcon2,data.name2,data.url2);
		setData(mTvName3,mIvIcon3,data.name3,data.url3);
//		mTv.setText(data.name1+" "+data.name2+" "+data.name3);

	}

	private void setData(TextView tv,ImageView iv,final String name,String url) {
		if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(url)) {
			tv.setText(name);
			iv.setImageResource(R.drawable.ic_default);
			BitmapHepler.display(iv, URLS.IMAGEBASEURL +url);
			ViewGroup parent = (ViewGroup) tv.getParent();
			parent.setVisibility(View.VISIBLE);
			parent.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Toast.makeText(UIUtils.getContext(), name, 0).show();
				}
			});
		}else{
			ViewGroup parent = (ViewGroup) tv.getParent();
			parent.setVisibility(View.INVISIBLE);
		}
		
	}

}
